<?php

use yii\helpers\Html;
use yii\helpers\Url;
use backend\widgets\GridView;
use yii\widgets\Breadcrumbs;
use yii\bootstrap\Modal;
use backend\models\service\AdminService as Admin;
$this->title = '合作账号列表';
Modal::begin([
    'id' => 'common-modal',
    'header' => '<h4 class="modal-title"></h4>',
    'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
]);


$js = <<<JS
$(".modaldialog").click(function(){ 
        aUrl = $(this).attr('data-url');
        aTitle = $(this).attr('data-title');
        $($(this).attr('data-target')+" .modal-title").text(aTitle);
        $($(this).attr('data-target')).modal("show")
             .find(".modal-body")
             .load(aUrl); 
        return false;
   }); 
$('#create').on('click', function () {
    $('.modal-title').html('创建栏目');
    $.get('create',
        function (data) {
      // 弹窗的主题渲染页面
            $('.modal-body').html(data);
        }  
    );
});
JS;
$this->registerJs($js);

Modal::end();
?>

<div class="RightCenter clear">

    <div class="RightTime">
        <div class="Time">
            <h3>合作账号列表</h3>
        </div>
    </div>
    <p style="margin:30px;"><?php
        echo Html::a('新建账号', 'create', [
            'class' => 'btn btn-success',
        ]);
        ?>
    </p>
    <div class="Read_date" style="margin-top:20px;margin-bottom: 5px;height:60px;">
        <ul>
            <li class="Read_LisJ" style="margin-top:12.5px;">
                <div class="Seek">
                    <input type="text" class="form-control AppIN" id="exampleInputAmount" placeholder="搜索合作账号名称" value="<?php echo isset($search['name']) ? trim($search['name']) : '';?>">
                    <button type="button" class="btn btn-primary SS">搜索</button>
                    <button class="btn btn-primary CZ" type="button">重置</button>
                </div>
            </li>
            <!--<div class="SX clear">-->
                <!--筛选:-->
<!--                 <select id="op">
                    <option value="">全部合作方</option>
                    <?php // foreach($cooperation as $c):?>
                        <option <?php // echo isset($select['AdminService']['id']) && $c['id'] == $select['AdminService']['id'] ? 'selected = "selected"' : '';?> value="<?php // echo $c['id'];?>"><?php // echo $c['username'];?></option>
                    <?php // endforeach;?>
                </select>-->
<!--                <select class="channels">
                    <option>全部渠道</option>
                    <?php // foreach($channel as $ch):?>
                        <option <?php // echo isset($select['TweetService']['channel_id']) && $ch['id'] == $select['TweetService']['channel_id'] ? 'selected = "selected"' : '';?> value="<?php // echo $ch['id'];?>"><?php // echo $ch['username'];?></option>
                    <?php // endforeach;?>
                </select>
                <select id="channel" style="display: none;">
                    <option>全部渠道</option>
                </select>-->
<!--                <button class="btn btn-primary czS" type="button">
                    重置
                </button>-->
            <!--</div>-->
        </ul>
    </div>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            [
                'attribute' => 'admin_sn',
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '合作账号',
                'headerOptions' => ['width' => 20],
            ],
            [
                'attribute' => 'username',
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '合作账号名称',
                'headerOptions' => ['width' => 30],
            ],
            [
                'label' => '渠道数量',
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'headerOptions' => ['width' => 30],
                'value' => function($data) {
            return Admin::getChannelNums($data->id, '3');
        }
            ],
            [
                'attribute' => 'remark',
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '备注',
                'headerOptions' => ['width' => 100],
            ],
            [
                'attribute' => 'create_time',
                'format' => 'raw',
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '创建时间',
                'headerOptions' => ['width' => 80],
            ],
            [
                'class' => \yii\grid\ActionColumn::className(),
                'header' => '操作',
                'headerOptions' => ['width' => 180],
                'contentOptions' => ['class' => 'action-link'],
                'template' => '{view} {update} {del}',
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                return Html::a('详细信息', $url) . " ";
            },
                    'update' => function ($url, $model, $key) {
                return Html::a('编辑', $url, [
                            'id' => 'channel-update',
                            'class' => 'modaldialog',
                            'data-toggle' => 'modal',
                            'data-url' => Url::toRoute($url),
                            'data-title' => '编辑',
                            'data-target' => '#common-modal',
                        ]) . " ";
            },
                    'del' => function ($url, $model, $key) {
                return Html::a('删除', $url, [
                            'data' => [
                                'confirm' => '确定/删除？',
                                'method' => 'post',
                            ],
                ]);
            },
                ],
            ],
        ],
    ]);
    ?>
</div>
<script>
    $(".SS").click(function(){
        var name = $("#exampleInputAmount").val();
        location.href="/admin/index?name="+name
    });
    
    $(".CZ").click(function(){
        location.href="/admin/index"
    });
    
//    $("#op").change(function(){
//        var op_id = $(this).val();
//        if(op_id == ''){
//            $(".channels").show();
//            $("#channel").hide();
//        }else{
//            $(".channels").hide();
//            get(op_id);
//        }
//    });
//    var cid = '<?php // echo isset($select['TweetService']['channel_id']) ? $select['TweetService']['channel_id'] : '';?>';
//    function get(id){
//        $("#channel").show();
//        $.ajax({
//            type:"post",
//            url:"/admin/get-channel-nums",
//            data:{pid:id,type:3},
//            success:function(msg){
//                $("#channel").empty();
//                var str = "<option value=''>全部渠道</option>"+msg;
//                $("#channel").append(str);
//                $("#channel").find("option[value='"+cid+"']").attr('selected','selected')
//            }
//        });
//    }
//    
//    $(function(){
//        var op_id = $("#op").val();
//        if(op_id == ''){
//            $(".channels").show();
//            $("#channel").hide();
//        }else{
//            $(".channels").hide();
//            get(op_id);
//        }
//    });
</script>